<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录界面</title>
    <script>
        onload = function () {
            document.getElementById("img").onclick = function () {
                this.src = "CodeServlet?date=" + new Date(); //点击图片刷新验证码
            }
        }
    </script>
    <style>
        body {
            background-image: url("img/preview2.jpg");

            font-size: 20px;
            font-family: Arial, sans-serif; /*设置字体样式*/
            text-align: center; /*文本居中*/
            display: flex;
            justify-content: center; /*水平居中*/
            align-items: center; /*垂直居中*/
            height: 100vh; /*设置全屏显示*/
            margin: 0; /*清除默认的margin值，*/

        }

        form {
            margin: 0;
            width: 300px;
            padding: 20px;
            background-color: rgba(232, 245, 233, 0.65); /* 设置背景色透明度 */
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
        }

        input[type="text"], input[type="password"], input[type="submit"], input[type="text"] {
            width: 100%;
            padding: 10px;
            margin: 5px 0;
            border: 1px solid transparent; /* 边框透明 */
            border-radius: 3px;
            box-sizing: border-box;
            background-color: rgba(255, 255, 255, 0.5); /* 设置输入框背景色透明度 */
        }

        input[type="submit"] {
            background-color: #007bff;
            color: #fff;
            cursor: pointer;
            opacity: 0.5; /* 设置透明度为50% */
        }

        .register-link {
            color: #007bff;
            text-decoration: none;
            font-size: 14px;
            margin-top: 10px;
            display: block;
        }

        /* 在此处添加CSS样式以增加间距 */
        #img {
            margin-right: 18px; /* 在图片和输入框之间增加10px的间距 */
        }
    </style>
</head>
<body>

<%

    Cookie[] cookies = request.getCookies();
    if(cookies != null){
        for (Cookie cookie:cookies) {
            // 判断cookie的名称
            switch (cookie.getName()){
                case "username":
                case "password":
                    request.setAttribute(cookie.getName(),cookie.getValue());
                    break;
            }
        }
    }
%>


<%--${msg}--%>
<form action="UserServlet">
    <h2>登录页面</h2>
    <span style="color: red;">${msg}</span><br>
    <input type="hidden" name="type" value="login">
    用户名<input type="text" name="username" value="${username}">

    <br>
    密码<input type="password" name="password" value="${password}">
    <br>
    <!-- 在验证码图片和输入框外添加一个div容器，并设置样式为flex布局 -->
    <div style="display: flex; align-items: center; justify-content: center;">
        <img src="CodeServlet" id="img" style="cursor: pointer;">
        <input type="text" name="code" style="width: 180px;">
    </div>
    记住我:<input type="checkbox" name="remember">
    免登录:<input type="checkbox" name="remember"><br/>
    <input type="submit" value="登录">
    <!-- 添加注册按钮和链接 -->
    <a href="register.jsp" class="register-link">注册</a>

</form>
</body>
</html>
